﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;

    public class JoinWorkExam : Page
    {
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected int intPaperID = 0;
        private PublicFun publicFun_0 = new PublicFun();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                this.intPaperID = Convert.ToInt32(base.Request["PaperID"].ToString());
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打13870606104进行咨询！');window.close();</script>");
                    }
                    else
                    {
                        base.Response.Write("<script>window.opener.location.href='FrmMyWorkExamList.aspx'</script>");
                        string str2 = "";
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand(string.Concat(new object[] { "select Flag,ExamName from WorkExamUser where UserCode='", this.httpCookie_0.Value.Trim(), "' and PaperID=", this.intPaperID }), connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            str2 = reader["Flag"].ToString();
                            reader["ExamName"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (str2 != "C")
                        {
                            string str = Convert.ToString(base.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
                            if (!(!(str == "") ? (str != null) : false))
                            {
                                str = Convert.ToString(base.Request.ServerVariables["REMOTE_ADDR"]);
                            }
                            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "delete from Systip where GetNumber='", this.httpCookie_0.Value, "' and Formtable='WorkPaperInfo' and FormID=", this.intPaperID, " ;update WorkExamUser set LastDate='", DateTime.Now.ToShortDateString(), "',LoginIP='", str, "' where UserCode='", this.httpCookie_0.Value.Trim(), "' and PaperID=", this.intPaperID }));
                        }
                        else
                        {
                            base.Response.Write("<script>alert('对不起，此份测评试卷您已经交卷，无法再操作！');window.close();</script>");
                        }
                    }
                }
            }
        }
    }
}

